<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>FFmpeg 备忘清单
 &#x26;  ffmpeg cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="本备忘清单是 FFmpeg 中常见视频处理操作的备忘清单

FFmpeg 参考，为开发人员分享快速参考备忘单。">
<meta keywords="ffmpeg,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="../style/style.css">
<link rel="stylesheet" href="../style/katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/ffmpeg.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js?v=1.5.5"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="ffmpeg-备忘清单"><svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="M21.72 17.91V6.5l-.53-.49L9.05 18.52l-1.29-.06L24 1.53l-.33-.95-11.93 1-5.75 6.6v-.23l4.7-5.39-1.38-.77-9.11.77v2.85l1.91.46v.01l.19-.01-.56.66v10.6c.609-.126 1.22-.241 1.83-.36L14.12 5.22l.83-.04L0 21.44l9.67.82 1.35-.77 6.82-6.74v2.15l-5.72 5.57 11.26.95.35-.94v-3.16l-3.29-.18a64.66 64.66 0 0 0 1.28-1.23z"></path>
</svg>
<a aria-hidden="true" tabindex="-1" href="#ffmpeg-备忘清单"><span class="icon icon-link"></span></a>FFmpeg 备忘清单</h1><div class="wrap-body">
<p>本备忘清单是 <a href="https://ffmpeg.org/">FFmpeg</a> 中常见视频处理操作的备忘清单</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#ffmpeg-参考">FFmpeg 参考</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装">安装</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#示例">示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#全局选项">全局选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#主要选项">主要选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#基础参数">基础参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#视频参数">视频参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#码率设置">码率设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#尺寸规格">尺寸规格</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#音频参数">音频参数</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#视频编辑">视频编辑</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#剪切视频部分">剪切视频部分</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#视频帧速率">视频帧速率</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#h265-2-pass-编码">H265 2-pass 编码</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#视频比特率设置">视频比特率设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#固定旋转">固定旋转</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#缩放到特定宽度">缩放到特定宽度</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#重新包装">重新包装</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#提取音频流">提取音频流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#提取视频流">提取视频流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#处理-id3-标签">处理 id3 标签</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#重新采样转换音频">重新采样/转换音频</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将输入文件转码为-dvd-pal-格式">将输入文件转码为 DVD PAL 格式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#-map-命令">-map 命令</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#反向--map-命令">反向 -map 命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#切换容器转换类型">切换容器(转换类型)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#音视频同步">音视频同步</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#图片中的视频">图片中的视频</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将视频拆分为图像">将视频拆分为图像</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#录屏">录屏</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#查找所有可用设备">查找所有可用设备</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#windows-下录屏">windows 下录屏</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#mac-下录屏">mac 下录屏</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#合并音频与图片">合并音频与图片</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#转换为-gif">转换为 Gif</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#转换为灰度">转换为灰度</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字幕格式转换">字幕格式转换</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字幕">字幕</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#制造-1-分钟的音频噪音">制造 1 分钟的音频噪音</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从视频中提取图像">从视频中提取图像</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#音量">音量</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将图像文件转换为其他格式">将图像文件转换为其他格式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将图像转换为-avi-文件">将图像转换为 AVI 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将-wav-文件转换为-mp3">将 WAV 文件转换为 MP3</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从视频中提取音频将其转码为-mp3">从视频中提取音频，将其转码为 MP3</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将-avi-转换为-flv">将 .avi 转换为 .flv</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将图片附加到-mp3">将图片附加到 mp3</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将视频与声音文件混合">将视频与声音文件混合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#编写带有-id3v23-页眉和-id3v1-页脚的-mp3">编写带有 ID3v2.3 页眉和 ID3v1 页脚的 mp3</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#连接输入文件">连接输入文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用比特率和-mp3-音频的编解码器对剪辑进行编码">使用比特率和 mp3 音频的编解码器对剪辑进行编码</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#将音频流与来自不同文件的视频流合并">将音频流与来自不同文件的视频流合并</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#合并视频">合并视频</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#视频过滤器">视频过滤器</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#格式">格式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#缩放">缩放</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#裁剪">裁剪</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#去除水印">去除水印</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建缩略图">创建缩略图</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加水印">添加水印</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#视频旋转">视频旋转</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#更改视频播放速度">更改视频播放速度</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加背景音乐">添加背景音乐</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#音频过滤器">音频过滤器</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#调节音量">调节音量</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#更改音频速度">更改音频速度</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#统一视频的音量">统一视频的音量</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#重新映射通道数">重新映射通道数</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#流处理">流处理</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#拉流">拉流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#推流">推流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#转发">转发</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="ffmpeg-参考"><a aria-hidden="true" tabindex="-1" href="#ffmpeg-参考"><span class="icon icon-link"></span></a>FFmpeg 参考</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="安装"><a aria-hidden="true" tabindex="-1" href="#安装"><span class="icon icon-link"></span></a>安装</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>Linux</p>
<pre><code class="code-highlight"><span class="code-line">$ apt-get install ffmpeg
</span><span class="code-line">$ yum install ffmpeg
</span></code></pre>
<p>MacOS</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ brew <span class="token function">install</span> ffmpeg
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="示例"><a aria-hidden="true" tabindex="-1" href="#示例"><span class="icon icon-link"></span></a>示例</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>mp4 转 avi:</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 output.avi
</span></code></pre>
<p>webm 转 mp4:</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> movie.webm movie.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="全局选项"><a aria-hidden="true" tabindex="-1" href="#全局选项"><span class="icon icon-link"></span></a>全局选项</h3><div class="wrap-body">

















<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-y</code></td><td>覆盖输出文件</td></tr><tr><td align="left"><code>-n</code></td><td>不要覆盖输出文件</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="主要选项"><a aria-hidden="true" tabindex="-1" href="#主要选项"><span class="icon icon-link"></span></a>主要选项</h3><div class="wrap-body">

























<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-f fmt</code></td><td>强制输入或输出文件格式</td></tr><tr><td align="left"><code>-i fName</code></td><td>输入文件名，未指定显示内容流的摘要</td></tr><tr><td align="left"><code>-c codecName</code></td><td>指定编解码器 [输入或输出]</td></tr><tr><td align="left"><code>-fs Nbytes</code></td><td>以 Nbytes 指定最大输出文件大小</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="基础参数"><a aria-hidden="true" tabindex="-1" href="#基础参数"><span class="icon icon-link"></span></a>基础参数</h3><div class="wrap-body">













































<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-codecs</code></td><td>列出可用编码</td></tr><tr><td align="left"><code>-formats</code></td><td>列出支持的格式</td></tr><tr><td align="left"><code>-protocols</code></td><td>列出支持的协议</td></tr><tr><td align="left"><code>-i input.mp4</code></td><td>指定输入文件</td></tr><tr><td align="left"><code>-c:v libx264</code></td><td>指定视频编码</td></tr><tr><td align="left"><code>-c:a aac</code></td><td>指定音频编码</td></tr><tr><td align="left"><code>-vcodec libx264</code></td><td>旧写法</td></tr><tr><td align="left"><code>-acodec aac</code></td><td>旧写法</td></tr><tr><td align="left"><code>-fs SIZE</code></td><td>指定文件大小</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="视频参数"><a aria-hidden="true" tabindex="-1" href="#视频参数"><span class="icon icon-link"></span></a>视频参数</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->





























































<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-b bRate</code></td><td>设置视频比特率(单位 kbit/s)</td></tr><tr><td align="left"><code>-fixaspect</code></td><td>固定纵横比</td></tr><tr><td align="left"><code>-bt tolerance</code></td><td>设置视频比特率容差(单位 kbit/s)</td></tr><tr><td align="left"><code>-maxrate bRate</code></td><td>设置最大视频比特率容差(单位 kbit/s)</td></tr><tr><td align="left"><code>-minrate bRate</code></td><td>设置最小视频比特率容差(单位 kbit/s)</td></tr><tr><td align="left"><code>-bufsize size</code></td><td>设置速率控制缓冲区大小(以 kByte 为单位)</td></tr><tr><td align="left"><code>-sameq</code></td><td>使用与源相同的视频质量(意味着 VBR)</td></tr><tr><td align="left"><code>-newvideo</code></td><td>将新的视频流添加到当前输出流</td></tr><tr><td align="left"><code>-aspect RATIO</code></td><td>纵横比(4:3、16:9 或 1.25)</td></tr><tr><td align="left"><code>-r RATE</code></td><td>每秒帧率</td></tr><tr><td align="left"><code>-s WIDTHxHEIGHT</code></td><td>帧大小</td></tr><tr><td align="left"><code>-vn</code></td><td>没有视频</td></tr><tr><td align="left"><code>-crf</code></td><td>指定编码的质量，数值越大压缩越高，一般范围是 18-28</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="码率设置"><a aria-hidden="true" tabindex="-1" href="#码率设置"><span class="icon icon-link"></span></a>码率设置</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token parameter variable">-b:v</span> 1M      <span class="token comment"># 视频比特率(1M = 1Mbit/s)</span>
</span><span class="code-line"><span class="token parameter variable">-b:a</span> 1M      <span class="token comment"># 音频比特率(1M = 1Mbit/s)</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="尺寸规格"><a aria-hidden="true" tabindex="-1" href="#尺寸规格"><span class="icon icon-link"></span></a>尺寸规格</h3><div class="wrap-body">















































<table><thead><tr><th align="left">:-</th><th>-</th><th>-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>K</code> 或 <code>k</code></td><td>103</td><td>1000 字节</td><td>千字节 Kilobytes</td></tr><tr><td align="left"><code>M</code></td><td>106</td><td>1000000 字节</td><td>兆字节 Megabytes</td></tr><tr><td align="left"><code>G</code></td><td>109</td><td>1000000000</td><td>千兆字节 Gigabytes</td></tr><tr><td align="left"><code>Ki</code></td><td>210</td><td>1024</td><td>千字节 Kibibyte</td></tr><tr><td align="left"><code>Mi</code></td><td>220</td><td>1048576</td><td>兆字节 Mebibyte</td></tr><tr><td align="left"><code>Gi</code></td><td>230</td><td>1073741824</td><td>Gibibyte</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="音频参数"><a aria-hidden="true" tabindex="-1" href="#音频参数"><span class="icon icon-link"></span></a>音频参数</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->









































<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-ab bRate</code></td><td>设置音频比特率(单位 kbit/s)</td></tr><tr><td align="left"><code>-aframes N</code></td><td>设置要录制的音频帧数 [-frames:a 的别名]</td></tr><tr><td align="left"><code>-aq q</code></td><td>设置音频质量(特定于编解码器，VBR) [-q:a 的别名]</td></tr><tr><td align="left"><code>-an</code></td><td>禁用录音</td></tr><tr><td align="left"><code>-acodec codec</code></td><td>设置音频编解码器。[-codec:a 的别名] 使用 'copy' 复制流。</td></tr><tr><td align="left"><code>-vol</code></td><td>以 256 的倍数更改音频音量，其中 256 = 100%(正常)音量。例如 512 = 200%</td></tr><tr><td align="left"><code>-newaudio</code></td><td>将新的音频流添加到当前输出流</td></tr><tr><td align="left"><code>-alang code</code></td><td>设置当前音频流的 ISO 639 语言代码(3 个字母)</td></tr></tbody></table>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="视频编辑"><a aria-hidden="true" tabindex="-1" href="#视频编辑"><span class="icon icon-link"></span></a>视频编辑</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="剪切视频部分"><a aria-hidden="true" tabindex="-1" href="#剪切视频部分"><span class="icon icon-link"></span></a>剪切视频部分</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 从1分45秒开始剪切2分35秒</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input<span class="token operator">></span> <span class="token parameter variable">-ss</span> 00:01:45 <span class="token parameter variable">-t</span> 00:02:35 <span class="token parameter variable">-vcodec</span> copy <span class="token parameter variable">-acodec</span> copy <span class="token operator">&#x3C;</span>output<span class="token operator">></span>
</span><span class="code-line"><span class="token comment"># 从1分45秒开始剪切到第4分20秒，与上一行等效</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input<span class="token operator">></span> <span class="token parameter variable">-ss</span> 00:01:45 <span class="token parameter variable">-to</span> 00:04:20 <span class="token parameter variable">-codec</span> copy <span class="token operator">&#x3C;</span>output<span class="token operator">></span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-ss</span> 00:00:30 <span class="token parameter variable">-i</span> orginalfile.mpg <span class="token parameter variable">-t</span> 00:00:05 <span class="token parameter variable">-vcodec</span> copy <span class="token parameter variable">-acodec</span> copy newfile.mpg
</span><span class="code-line"><span class="token comment"># 从 4.5 秒开始的 5 秒长的视频</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> in.mp4 <span class="token parameter variable">-ss</span> <span class="token number">4.5</span> <span class="token parameter variable">-t</span> <span class="token number">5</span> out.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="视频帧速率"><a aria-hidden="true" tabindex="-1" href="#视频帧速率"><span class="icon icon-link"></span></a>视频帧速率</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.avi <span class="token parameter variable">-r</span> <span class="token number">24</span> output.avi
</span></code></pre>
<p>将输出文件的帧速率强制为 24 fps</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-r</span> <span class="token number">1</span> <span class="token parameter variable">-i</span> input.m2v <span class="token parameter variable">-r</span> <span class="token number">24</span> output.avi
</span></code></pre>
<p>将输入文件的帧速率(仅对原始格式有效)强制为 1 fps，将输出文件的帧速率强制为 24 fps</p>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="h265-2-pass-编码"><a aria-hidden="true" tabindex="-1" href="#h265-2-pass-编码"><span class="icon icon-link"></span></a>H265 2-pass 编码</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-y</span> <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input<span class="token operator">></span> <span class="token parameter variable">-c:v</span> libx265 <span class="token parameter variable">-b:v</span> 2600k <span class="token punctuation">\</span>
</span><span class="code-line">  -x265-params <span class="token assign-left variable">pass</span><span class="token operator">=</span><span class="token number">1</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-an</span> <span class="token parameter variable">-f</span> mp4 /dev/null <span class="token operator">&#x26;&#x26;</span> <span class="token punctuation">\</span>
</span><span class="code-line">    ffmpeg <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input<span class="token operator">></span> <span class="token punctuation">\</span>
</span><span class="code-line">        <span class="token parameter variable">-c:v</span> libx265 <span class="token parameter variable">-b:v</span> 2600k <span class="token punctuation">\</span>
</span><span class="code-line">        -x265-params <span class="token assign-left variable">pass</span><span class="token operator">=</span><span class="token number">2</span> <span class="token punctuation">\</span>
</span><span class="code-line">        <span class="token parameter variable">-c:a</span> aac <span class="token parameter variable">-b:a</span> 128k output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>对于 <code>H265 2-pass</code> 编码，您需要组合 <code>2</code> 个 <code>ffmpeg</code> 调用</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="视频比特率设置"><a aria-hidden="true" tabindex="-1" href="#视频比特率设置"><span class="icon icon-link"></span></a>视频比特率设置</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.avi <span class="token parameter variable">-b:v</span> 64k <span class="token parameter variable">-bufsize</span> 64k output.avi
</span></code></pre>
<p>将输出文件的视频比特率设置为 64 kbit/s</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="固定旋转"><a aria-hidden="true" tabindex="-1" href="#固定旋转"><span class="icon icon-link"></span></a>固定旋转</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input<span class="token operator">></span> <span class="token parameter variable">-c</span> copy -metadata:s:v:0 <span class="token assign-left variable">rotate</span><span class="token operator">=</span><span class="token number">90</span> <span class="token operator">&#x3C;</span>output<span class="token operator">></span>
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>不要为旋转重新编码，而是简单地为旋转角度添加一个视频元数据字段</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="缩放到特定宽度"><a aria-hidden="true" tabindex="-1" href="#缩放到特定宽度"><span class="icon icon-link"></span></a>缩放到特定宽度</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> in.mp4 <span class="token parameter variable">-filter:v</span> <span class="token assign-left variable">scale</span><span class="token operator">=</span><span class="token string">"538:trunc(ow/a/2)*2"</span> <span class="token parameter variable">-c:a</span> copy out.mp4
</span></code></pre>
<p>给定所需的视频宽度，例如 538 像素，您可以使用以下方法将视频调整为该宽度，同时保持宽高比</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="重新包装"><a aria-hidden="true" tabindex="-1" href="#重新包装"><span class="icon icon-link"></span></a>重新包装</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="提取音频流"><a aria-hidden="true" tabindex="-1" href="#提取音频流"><span class="icon icon-link"></span></a>提取音频流</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.mp4 <span class="token parameter variable">-vn</span> <span class="token parameter variable">-c</span> copy output.aac 
</span></code></pre>
<!--rehype:className=wrap-text -->
<p><code>-vn</code> (过滤视频)，使用 <code>-c copy</code>，不会重新解码和编码，加快速度。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="提取视频流"><a aria-hidden="true" tabindex="-1" href="#提取视频流"><span class="icon icon-link"></span></a>提取视频流</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.mp4 <span class="token parameter variable">-an</span> <span class="token parameter variable">-c</span> copy output.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="处理-id3-标签"><a aria-hidden="true" tabindex="-1" href="#处理-id3-标签"><span class="icon icon-link"></span></a>处理 id3 标签</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>提取</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.mp3 <span class="token parameter variable">-f</span> ffmetadata metadata.txt
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>设置</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.mp3 <span class="token parameter variable">-acodec</span> copy <span class="token parameter variable">-metadata</span> <span class="token assign-left variable">title</span><span class="token operator">=</span><span class="token string">"&#x3C;title>"</span> <span class="token parameter variable">-metadata</span> <span class="token assign-left variable">artist</span><span class="token operator">=</span><span class="token string">"&#x3C;artist>"</span> <span class="token parameter variable">-metadata</span> <span class="token assign-left variable">album</span><span class="token operator">=</span><span class="token string">"&#x3C;album>"</span> out.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>更多<a href="https://gist.github.com/eyecatchup/0757b3d8b989fe433979db2ea7d95a01">请查看</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="重新采样转换音频"><a aria-hidden="true" tabindex="-1" href="#重新采样转换音频"><span class="icon icon-link"></span></a>重新采样/转换音频</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.aac <span class="token parameter variable">-acodec</span> mp3 <span class="token parameter variable">-ar</span> <span class="token number">44100</span> <span class="token parameter variable">-ab</span> <span class="token number">128000</span> output.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将输入文件转码为-dvd-pal-格式"><a aria-hidden="true" tabindex="-1" href="#将输入文件转码为-dvd-pal-格式"><span class="icon icon-link"></span></a>将输入文件转码为 DVD PAL 格式</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-y</span> <span class="token parameter variable">-threads</span> <span class="token number">8</span> <span class="token parameter variable">-i</span> inFile <span class="token parameter variable">-target</span> pal-dvd <span class="token parameter variable">-ac</span> <span class="token number">2</span> <span class="token parameter variable">-aspect</span> <span class="token number">16</span>:9 <span class="token parameter variable">-acodec</span> mp2 <span class="token parameter variable">-ab</span> <span class="token number">224000</span> <span class="token parameter variable">-vf</span> <span class="token assign-left variable">pad</span><span class="token operator">=</span><span class="token number">0</span>:­0:0:0 outFile
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="-map-命令"><a aria-hidden="true" tabindex="-1" href="#-map-命令"><span class="icon icon-link"></span></a>-map 命令</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p><code>-map</code> 命令用于指定索引文件，以及索引文件中流类型和它的索引</p>
<hr>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token parameter variable">-map</span> index:stram_type:stream_index
</span></code></pre>
<hr>





















<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>input_file_index</code></td><td>输入的文件索引(从 0 开始)</td></tr><tr><td align="left"><code>stream_type</code></td><td>指定文件流的类型(a -> 音频，v -> 视频，s -> 字幕)</td></tr><tr><td align="left"><code>stream_index</code></td><td>指定流类型的索引(从 0 开始)</td></tr></tbody></table>
<p>将第一个输入文件的第二个音频拷贝到 out.mp3</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-map</span> <span class="token number">0</span>:a:1 <span class="token parameter variable">-c</span> copy out.mp3
</span></code></pre>
<p>将第一个输入文件的视频流和第二个输入文件的音频流拷贝到 out.mp4</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> i1.mp4 <span class="token parameter variable">-i</span> i2.mp4 <span class="token parameter variable">-map</span> <span class="token number">0</span>:v <span class="token parameter variable">-map</span> <span class="token number">0</span>:a <span class="token parameter variable">-c</span> copy out.mp4
</span></code></pre>
<h4 id="反向--map-命令"><a aria-hidden="true" tabindex="-1" href="#反向--map-命令"><span class="icon icon-link"></span></a>反向 -map 命令</h4>
<!--rehype:wrap-class=col-span-2-->
<p class="wrap-text ">反向的 map 命令（在 map 命令的参数前加负号）。例如，<code>-map -0:a:0</code>，忽略第一个文件中的第一个音频流。</p>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="切换容器转换类型"><a aria-hidden="true" tabindex="-1" href="#切换容器转换类型"><span class="icon icon-link"></span></a>切换容器(转换类型)</h3><div class="wrap-body">
<p>将容器从 <code>MKV</code> 更改为 <code>MP4</code></p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> file.mkv <span class="token parameter variable">-acodec</span> copy <span class="token parameter variable">-vcodec</span> copy file.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>要将视频从 <code>.mov</code> 更改为 <code>.mp4</code></p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> in.mov out.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="音视频同步"><a aria-hidden="true" tabindex="-1" href="#音视频同步"><span class="icon icon-link"></span></a>音视频同步</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>将音频延迟 3 秒</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-itsoffset</span> <span class="token number">3</span> <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-map</span> <span class="token number">0</span>:v <span class="token parameter variable">-map</span> <span class="token number">1</span>:a <span class="token parameter variable">-codec:a</span> copy <span class="token parameter variable">-codec:v</span> copy output.mov
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>将视频延迟 3 秒(即将音频提前 3 秒)</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-itsoffset</span> <span class="token number">3</span> <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-map</span> <span class="token number">1</span>:v <span class="token parameter variable">-map</span> <span class="token number">0</span>:a <span class="token parameter variable">-codec:a</span> copy <span class="token parameter variable">-codec:v</span> copy output.mov
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="图片中的视频"><a aria-hidden="true" tabindex="-1" href="#图片中的视频"><span class="icon icon-link"></span></a>图片中的视频</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> image2 <span class="token parameter variable">-i</span> image%d.jpg video.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>多个编号的图像 image1.jpg、image2.jpg... 像这样从它们创建一个视频</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将视频拆分为图像"><a aria-hidden="true" tabindex="-1" href="#将视频拆分为图像"><span class="icon icon-link"></span></a>将视频拆分为图像</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> video.mp4 image%d.jpg
</span></code></pre>
</div></div></div><div class="wrap h3body-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="录屏"><a aria-hidden="true" tabindex="-1" href="#录屏"><span class="icon icon-link"></span></a>录屏</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<h4 id="查找所有可用设备"><a aria-hidden="true" tabindex="-1" href="#查找所有可用设备"><span class="icon icon-link"></span></a>查找所有可用设备</h4>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> avfoundation <span class="token parameter variable">-list_devices</span> <span class="token boolean">true</span> <span class="token parameter variable">-i</span> <span class="token string">""</span>
</span></code></pre>
<!--rehype:className=wrap-text -->
<p><span style="color:red">一定要选择好设备，根据设备进行配置。</span></p>
<h4 id="windows-下录屏"><a aria-hidden="true" tabindex="-1" href="#windows-下录屏"><span class="icon icon-link"></span></a>windows 下录屏</h4>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-hide_banner</span> <span class="token parameter variable">-loglevel</span> error <span class="token parameter variable">-stats</span> <span class="token parameter variable">-f</span> gdigrab <span class="token parameter variable">-framerate</span> <span class="token number">60</span> <span class="token punctuation">\</span>
</span><span class="code-line"><span class="token parameter variable">-offset_x</span> <span class="token number">0</span> <span class="token parameter variable">-offset_y</span> <span class="token number">0</span> <span class="token parameter variable">-video_size</span> 1920x1080 <span class="token parameter variable">-draw_mouse</span> <span class="token number">1</span> <span class="token parameter variable">-i</span> deskop <span class="token punctuation">\</span>
</span><span class="code-line"><span class="token parameter variable">-c:v</span> libx264 <span class="token parameter variable">-r</span> <span class="token number">60</span> <span class="token parameter variable">-preset</span> ultrafast <span class="token parameter variable">-pix_fmt</span> yuv420p <span class="token parameter variable">-y</span> screen_record.mp4
</span></code></pre>
<h4 id="mac-下录屏"><a aria-hidden="true" tabindex="-1" href="#mac-下录屏"><span class="icon icon-link"></span></a>mac 下录屏</h4>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> avfoundation <span class="token parameter variable">-i</span> <span class="token number">1</span>:0 <span class="token parameter variable">-preset</span> ultrafast out.mkv
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="合并音频与图片"><a aria-hidden="true" tabindex="-1" href="#合并音频与图片"><span class="icon icon-link"></span></a>合并音频与图片</h3><div class="wrap-body">
<p>合并多个音频，自定义背景图片，生成视频音乐</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># mylist.txt >>></span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'1.mp3'</span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'2.mp3'</span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'3.mp3'</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment"># OBS: 46500 = 25:50 minutes * 60 * 30fps</span>
</span><span class="code-line"><span class="token comment"># echo "00:25:50" | awk -F: '{ print (($1 * 3600) + ($2 * 60) + $3) * 30 }'</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-y</span> <span class="token parameter variable">-loop</span> <span class="token number">1</span> <span class="token parameter variable">-i</span> cover.jpg <span class="token parameter variable">-f</span> concat <span class="token parameter variable">-i</span> mylist.txt <span class="token parameter variable">-c:v</span> libx264 <span class="token parameter variable">-r</span> <span class="token number">30</span> <span class="token parameter variable">-pix_fmt</span> yuv420p <span class="token parameter variable">-vframes</span> <span class="token number">46500</span> <span class="token parameter variable">-c:a</span> aac <span class="token parameter variable">-b:a</span> 192k <span class="token parameter variable">-strict</span> experimental <span class="token parameter variable">-shortest</span> output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-3"><div class="wrap-header h3wrap"><h3 id="转换为-gif"><a aria-hidden="true" tabindex="-1" href="#转换为-gif"><span class="icon icon-link"></span></a>转换为 Gif</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-3-->
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-ss</span> <span class="token number">2</span> <span class="token parameter variable">-t</span> <span class="token number">28</span> <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"fps=10,scale=1080:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"</span> <span class="token parameter variable">-loop</span> <span class="token number">0</span> output.gif
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>上面有关更多信息，请参阅 <a href="https://superuser.com/a/556031">StackOverflow 问题</a></p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 转换为 GIF</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov output.gif
</span><span class="code-line"><span class="token comment"># 从 GIF 转换</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.gif output.mov
</span><span class="code-line"><span class="token comment"># 在非 GIF 格式之间转换</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-codec:v</span> copy <span class="token parameter variable">-codec:a</span> copy output.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="转换为灰度"><a aria-hidden="true" tabindex="-1" href="#转换为灰度"><span class="icon icon-link"></span></a>转换为灰度</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-y</span> <span class="token parameter variable">-i</span> inFile <span class="token parameter variable">-flags</span> gray outFile
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="字幕格式转换"><a aria-hidden="true" tabindex="-1" href="#字幕格式转换"><span class="icon icon-link"></span></a>字幕格式转换</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># srt -> ass</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> subtitle.srt subtitle.ass
</span><span class="code-line"><span class="token comment"># ass -> vtt</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> subtitle.ass subtitle.vtt
</span></code></pre>
<p class="wrap-text ">srt、ass、vtt 等格式之间可以相互转换</p>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="字幕"><a aria-hidden="true" tabindex="-1" href="#字幕"><span class="icon icon-link"></span></a>字幕</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>将字幕写入视频</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-filter:v</span> <span class="token string">'subtitles=subtitles.srt'</span> <span class="token parameter variable">-codec:a</span> copy output.mov
</span></code></pre>
<p>将字幕写入视频，具有自定义字幕样式</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-filter:v</span> <span class="token string">"subtitles=subtitles.srt:force_style='FontName=Menlo Bold,Fontsize=18'"</span> <span class="token parameter variable">-codec:a</span> copy output.mov
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="制造-1-分钟的音频噪音"><a aria-hidden="true" tabindex="-1" href="#制造-1-分钟的音频噪音"><span class="icon icon-link"></span></a>制造 1 分钟的音频噪音</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-ar</span> <span class="token number">48000</span> <span class="token parameter variable">-t</span> <span class="token number">60</span> <span class="token parameter variable">-f</span> s16le <span class="token parameter variable">-acodec</span> pcm_s16le <span class="token parameter variable">-i</span> /dev/u­random <span class="token parameter variable">-ab</span> 64K <span class="token parameter variable">-f</span> mp2 <span class="token parameter variable">-acodec</span> mp2 <span class="token parameter variable">-y</span> noise.mp2
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="从视频中提取图像"><a aria-hidden="true" tabindex="-1" href="#从视频中提取图像"><span class="icon icon-link"></span></a>从视频中提取图像</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> foo.avi <span class="token parameter variable">-r</span> <span class="token number">1</span> <span class="token parameter variable">-s</span> WxH <span class="token parameter variable">-f</span> image2 outFil­e%0­3d.png
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-2"><div class="wrap-header h3wrap"><h3 id="音量"><a aria-hidden="true" tabindex="-1" href="#音量"><span class="icon icon-link"></span></a>音量</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-2-->
<p>将音量减半</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-codec:v</span> copy <span class="token parameter variable">-filter:a</span> <span class="token string">'volume=0.5'</span> output.mov
</span></code></pre>
<p>音量加倍</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-codec:v</span> copy <span class="token parameter variable">-filter:a</span> <span class="token string">'volume=2'</span> output.mov
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将图像文件转换为其他格式"><a aria-hidden="true" tabindex="-1" href="#将图像文件转换为其他格式"><span class="icon icon-link"></span></a>将图像文件转换为其他格式</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> foo012­2.png foo.tiff 
</span></code></pre>
<p>pgm, ppm, pam, pgmyuv, jpeg, gif, png, tiff, sgi</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将图像转换为-avi-文件"><a aria-hidden="true" tabindex="-1" href="#将图像转换为-avi-文件"><span class="icon icon-link"></span></a>将图像转换为 AVI 文件</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> image2 <span class="token parameter variable">-i</span> foo-%0­3d.jpeg <span class="token parameter variable">-r</span> <span class="token number">12</span> <span class="token parameter variable">-s</span> WxH foo.avi
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将-wav-文件转换为-mp3"><a aria-hidden="true" tabindex="-1" href="#将-wav-文件转换为-mp3"><span class="icon icon-link"></span></a>将 WAV 文件转换为 MP3</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> source­_so­ng.wav <span class="token parameter variable">-vn</span> <span class="token parameter variable">-ar</span> <span class="token number">44100</span> <span class="token parameter variable">-ac</span> <span class="token number">2</span> <span class="token parameter variable">-ab</span> <span class="token number">192</span> <span class="token parameter variable">-f</span> mp3 final_­son­g.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="从视频中提取音频将其转码为-mp3"><a aria-hidden="true" tabindex="-1" href="#从视频中提取音频将其转码为-mp3"><span class="icon icon-link"></span></a>从视频中提取音频，将其转码为 MP3</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> source.avi <span class="token parameter variable">-vn</span> <span class="token parameter variable">-ar</span> <span class="token number">44100</span> <span class="token parameter variable">-ac</span> <span class="token number">2</span> <span class="token parameter variable">-ab</span> <span class="token number">192</span> <span class="token parameter variable">-f</span> mp3 sound.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将-avi-转换为-flv"><a aria-hidden="true" tabindex="-1" href="#将-avi-转换为-flv"><span class="icon icon-link"></span></a>将 .avi 转换为 .flv</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> source.avi <span class="token parameter variable">-ab</span> <span class="token number">56</span> <span class="token parameter variable">-ar</span> <span class="token number">44100</span> <span class="token parameter variable">-b</span> <span class="token number">200</span> <span class="token parameter variable">-r</span> <span class="token number">15</span> <span class="token parameter variable">-s</span> 320x240 <span class="token parameter variable">-f</span> flv output.flv
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将图片附加到-mp3"><a aria-hidden="true" tabindex="-1" href="#将图片附加到-mp3"><span class="icon icon-link"></span></a>将图片附加到 mp3</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp3 <span class="token parameter variable">-i</span> cover.png <span class="token parameter variable">-c</span> copy -metad­ata:s:v <span class="token assign-left variable">title</span><span class="token operator">=</span>­<span class="token string">"­Album cover"</span> -metad­ata:s:v commen­t<span class="token operator">=</span><span class="token string">"Cover (Front­)"</span> out.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将视频与声音文件混合"><a aria-hidden="true" tabindex="-1" href="#将视频与声音文件混合"><span class="icon icon-link"></span></a>将视频与声音文件混合</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> song.wav <span class="token parameter variable">-i</span> source­_vi­deo.avi outvid­eo.mpg
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="编写带有-id3v23-页眉和-id3v1-页脚的-mp3"><a aria-hidden="true" tabindex="-1" href="#编写带有-id3v23-页眉和-id3v1-页脚的-mp3"><span class="icon icon-link"></span></a>编写带有 ID3v2.3 页眉和 ID3v1 页脚的 mp3</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> inFile -id3v2­_ve­rsion <span class="token number">3</span> -write­_id3v1 <span class="token number">1</span> outFil­e.mp3
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="连接输入文件"><a aria-hidden="true" tabindex="-1" href="#连接输入文件"><span class="icon icon-link"></span></a>连接输入文件</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">cat</span> inFile1 inFile2 <span class="token operator">|</span> ffmpeg <span class="token parameter variable">-f</span> mpeg <span class="token parameter variable">-i</span> - <span class="token parameter variable">-vcodec</span> copy <span class="token parameter variable">-acodec</span> copy outFil­e.mpg
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="使用比特率和-mp3-音频的编解码器对剪辑进行编码"><a aria-hidden="true" tabindex="-1" href="#使用比特率和-mp3-音频的编解码器对剪辑进行编码"><span class="icon icon-link"></span></a>使用比特率和 mp3 音频的编解码器对剪辑进行编码</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> clip.avi <span class="token parameter variable">-vcodec</span> libxvid <span class="token parameter variable">-b</span> <span class="token number">800000</span> <span class="token parameter variable">-acodec</span> libmp3lame <span class="token parameter variable">-ab</span> <span class="token number">128</span> new-cl­ip.avi
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="将音频流与来自不同文件的视频流合并"><a aria-hidden="true" tabindex="-1" href="#将音频流与来自不同文件的视频流合并"><span class="icon icon-link"></span></a>将音频流与来自不同文件的视频流合并</h3><div class="wrap-body">
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> audioS.mp4 <span class="token parameter variable">-i</span> videoS.mp4 <span class="token parameter variable">-c</span> copy <span class="token parameter variable">-map</span> <span class="token number">0</span>:a <span class="token parameter variable">-map</span> <span class="token number">1</span>:v outFil­e.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist col-span-3 row-span-3"><div class="wrap-header h3wrap"><h3 id="合并视频"><a aria-hidden="true" tabindex="-1" href="#合并视频"><span class="icon icon-link"></span></a>合并视频</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-3 row-span-3-->
<p>合并相同规格(解码/分辨率/帧率)视频</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># mylist.txt >>></span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'1.mp4'</span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'2.mp4'</span>
</span><span class="code-line"><span class="token function">file</span> <span class="token string">'3.mp4'</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment"># 这些文件是相对路径，如使用绝对路径需要添加 `-safe 0` 参数</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> concat <span class="token parameter variable">-i</span> mylist.txt <span class="token parameter variable">-c</span> copy output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>合并当前目录下所有视频</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> concat <span class="token parameter variable">-safe</span> <span class="token number">0</span> <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span><span class="token punctuation">(</span><span class="token keyword">for</span> <span class="token for-or-select variable">f</span> <span class="token keyword">in</span> ./*.mp4<span class="token punctuation">;</span> <span class="token keyword">do</span> <span class="token builtin class-name">echo</span> <span class="token string">"file '<span class="token environment constant">$PWD</span>/<span class="token variable">$f</span>'"</span><span class="token punctuation">;</span> <span class="token keyword">done</span><span class="token punctuation">)</span> <span class="token parameter variable">-c</span> copy output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>合并不同规格视频，保证视频不变形</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token number">1</span>.mp4 <span class="token parameter variable">-c</span> copy <span class="token parameter variable">-bsf:v</span> h264_mp4toannexb <span class="token parameter variable">-f</span> mpegts tmp1.ts
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token number">2</span>.mp4 <span class="token parameter variable">-c</span> copy <span class="token parameter variable">-bsf:v</span> h264_mp4toannexb <span class="token parameter variable">-f</span> mpegts tmp2.ts
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token number">3</span>.mp4 <span class="token parameter variable">-c</span> copy <span class="token parameter variable">-bsf:v</span> h264_mp4toannexb <span class="token parameter variable">-f</span> mpegts tmp3.ts
</span><span class="code-line">
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-threads</span> <span class="token number">2</span> <span class="token parameter variable">-i</span> <span class="token string">"concat:tmp1.ts|tmp2.ts|tmp3.ts"</span>  <span class="token parameter variable">-vf</span> <span class="token string">"scale=720:1080:force_original_aspect_ratio=decrease,pad=720:1080:(ow-iw)/2:(oh-ih)/2"</span> <span class="token parameter variable">-pix_fmt</span> yuvj420p <span class="token parameter variable">-shortest</span> <span class="token parameter variable">-y</span> output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>合并不同解码视频</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input1.mp4 <span class="token parameter variable">-i</span> input2.webm <span class="token parameter variable">-i</span> input3.mov <span class="token punctuation">\</span>
</span><span class="code-line"><span class="token parameter variable">-filter_complex</span> <span class="token string">"[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]"</span> <span class="token punctuation">\</span>
</span><span class="code-line"><span class="token parameter variable">-map</span> <span class="token string">"[outv]"</span> <span class="token parameter variable">-map</span> <span class="token string">"[outa]"</span> output.mkv
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>合并视频并重新编码音频</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-f</span> concat <span class="token parameter variable">-i</span> mylist.txt <span class="token parameter variable">-c:v</span> copy <span class="token parameter variable">-c:a</span> flac <span class="token parameter variable">-strict</span> <span class="token parameter variable">-2</span> output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="视频过滤器"><a aria-hidden="true" tabindex="-1" href="#视频过滤器"><span class="icon icon-link"></span></a>视频过滤器</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="格式"><a aria-hidden="true" tabindex="-1" href="#格式"><span class="icon icon-link"></span></a>格式</h3><div class="wrap-body">
<p>如果一个 fliter 有多个参数，需要使用 <code>,</code> 分隔</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> test.avi <span class="token parameter variable">-c:v</span> libx264 <span class="token parameter variable">-vf</span> <span class="token string">"scale=1024:-1,transpose=1,crop=iw/3:ih/3"</span> output.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="缩放"><a aria-hidden="true" tabindex="-1" href="#缩放"><span class="icon icon-link"></span></a>缩放</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"scale=640:480"</span> out.mp4
</span><span class="code-line"><span class="token comment"># -1 → 指根据另一个参数帮我们推断</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"scale=720:-1"</span> out.mp4
</span><span class="code-line"><span class="token comment"># 宽度和高度</span>
</span><span class="code-line">ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"scale=w=800:h=600"</span> output.mp4
</span><span class="code-line"><span class="token comment"># in_w\in_h 输入尺寸</span>
</span><span class="code-line">ffmpeg <span class="token parameter variable">-i</span> input.mkv <span class="token parameter variable">-vf</span> <span class="token string">"scale=w=1/2*in_w:h=1/2*in_h"</span> output.mkv
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="裁剪"><a aria-hidden="true" tabindex="-1" href="#裁剪"><span class="icon icon-link"></span></a>裁剪</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>从左上角开始，复制 <code>x=0px</code> <code>y=0px</code> 的相应窗口来创建 <code>1280x720</code> 大小的输出视频</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"crop=w=1280:h=720:x=0:y=0"</span> output.mp4
</span></code></pre>
<p>裁剪到宽度 360，高度 640，从坐标 (10, 20) 开始</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mov <span class="token parameter variable">-vf</span> <span class="token string">'crop=360:640:10:20'</span> output.mov
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="去除水印"><a aria-hidden="true" tabindex="-1" href="#去除水印"><span class="icon icon-link"></span></a>去除水印</h3><div class="wrap-body">
<p>设置一个矩形覆盖区域 x=10:y=10:w=120:h=45</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># show=1 为可选参数，设置显示边框，方便调试用的</span>
</span><span class="code-line">ffmpeg <span class="token parameter variable">-i</span> <span class="token number">1</span>.mp4 <span class="token parameter variable">-b:v</span> 548k <span class="token parameter variable">-vf</span> <span class="token assign-left variable">delogo</span><span class="token operator">=</span>x<span class="token operator">=</span><span class="token number">10</span>:y<span class="token operator">=</span><span class="token number">10</span>:w<span class="token operator">=</span><span class="token number">120</span>:h<span class="token operator">=</span><span class="token number">45</span>:show<span class="token operator">=</span><span class="token number">1</span> output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建缩略图"><a aria-hidden="true" tabindex="-1" href="#创建缩略图"><span class="icon icon-link"></span></a>创建缩略图</h3><div class="wrap-body">
<p>在 10 秒时创建一个缩略图</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-ss</span> <span class="token number">10</span> <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input file<span class="token operator">></span> <span class="token parameter variable">-vframes</span> <span class="token number">1</span> <span class="token parameter variable">-vcodec</span> png <span class="token parameter variable">-an</span> thumb.png
</span></code></pre>
<!--rehype:className=wrap-text -->
<p>例如，要每 <code>n</code> 秒创建一次缩略图，请使用 <code>-vf fps=1/n</code></p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token operator">&#x3C;</span>input file<span class="token operator">></span> <span class="token parameter variable">-vf</span> <span class="token assign-left variable">fps</span><span class="token operator">=</span><span class="token number">1</span>/60 thumbnails/thumb%03d.png
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="添加水印"><a aria-hidden="true" tabindex="-1" href="#添加水印"><span class="icon icon-link"></span></a>添加水印</h3><div class="wrap-body">
<p>在视频左上方 20,20 的位置插入 logo.png 图片</p>
<pre class="wrap-text "><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># -b:v 548k 可选参数，设置视频比特率，默认 200k 最好设置与原视频一致</span>
</span><span class="code-line">ffmpeg <span class="token parameter variable">-i</span> <span class="token number">1</span>.mp4 <span class="token parameter variable">-acodec</span> copy <span class="token parameter variable">-b:v</span> 548k <span class="token parameter variable">-vf</span> <span class="token string">"movie=logo.png[watermark];[in][watermark]overlay=20:20"</span> output.mp4
</span></code></pre>
<!--rehype:className=wrap-text -->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="视频旋转"><a aria-hidden="true" tabindex="-1" href="#视频旋转"><span class="icon icon-link"></span></a>视频旋转</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 顺时针旋转 90</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.avi <span class="token parameter variable">-vf</span> <span class="token string">"rotate=90*PI/180"</span> out.mp4 
</span><span class="code-line"><span class="token comment"># 顺时针旋转 180，翻转 90</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"rotate=PI"</span> out.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="更改视频播放速度"><a aria-hidden="true" tabindex="-1" href="#更改视频播放速度"><span class="icon icon-link"></span></a>更改视频播放速度</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 加速 2 倍</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mkv <span class="token parameter variable">-vf</span> <span class="token string">"setpts=0.5*PTS"</span> output.mkv 
</span><span class="code-line"><span class="token comment"># 减速 2 倍</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp4 <span class="token parameter variable">-vf</span> <span class="token string">"setpts=2*PTS"</span> output.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="添加背景音乐"><a aria-hidden="true" tabindex="-1" href="#添加背景音乐"><span class="icon icon-link"></span></a>添加背景音乐</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># -t 10 文件时长，单位为秒，建议取值原始视频总时长</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token number">1</span>.mp4 <span class="token parameter variable">-i</span> test.mp3 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-filter_complex</span> <span class="token string">"[1:a]aloop=loop=-1:size=2e+09[out];[out][0:a]amix"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-t</span> <span class="token number">10</span> out.mp4
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="音频过滤器"><a aria-hidden="true" tabindex="-1" href="#音频过滤器"><span class="icon icon-link"></span></a>音频过滤器</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="调节音量"><a aria-hidden="true" tabindex="-1" href="#调节音量"><span class="icon icon-link"></span></a>调节音量</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 增大音量</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> test.mp4 <span class="token parameter variable">-af</span> <span class="token string">"volumn=1.5"</span> out.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="更改音频速度"><a aria-hidden="true" tabindex="-1" href="#更改音频速度"><span class="icon icon-link"></span></a>更改音频速度</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.wav <span class="token parameter variable">-af</span> <span class="token string">"atempo=0.75"</span> output.wav 
</span><span class="code-line"><span class="token comment"># 加速 4 倍</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp3 <span class="token parameter variable">-af</span> <span class="token string">"atempo=2.0,atempo=2.0"</span> ouutput.mp3
</span></code></pre>
<p><code>atempo</code> 它只接受 <code>0.5</code>(半速) 到 <code>2</code> (倍速)之间的值。为了越过这个限制，你可以链式使用这个过滤器</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="统一视频的音量"><a aria-hidden="true" tabindex="-1" href="#统一视频的音量"><span class="icon icon-link"></span></a>统一视频的音量</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> test.mp4 <span class="token parameter variable">-af</span> <span class="token string">"loudnorm=I=-5:LRA=1"</span> out.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="重新映射通道数"><a aria-hidden="true" tabindex="-1" href="#重新映射通道数"><span class="icon icon-link"></span></a>重新映射通道数</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 使左右耳的声音同时出现</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> input.mp3 <span class="token parameter variable">-af</span> <span class="token string">"channelmap=1-0|1-1"</span> output.mp3
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="流处理"><a aria-hidden="true" tabindex="-1" href="#流处理"><span class="icon icon-link"></span></a>流处理</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="拉流"><a aria-hidden="true" tabindex="-1" href="#拉流"><span class="icon icon-link"></span></a>拉流</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 拉取rtmp流并存储到本地</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token string">"rtsp://127.0.0.1/test"</span> test.mp4
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="推流"><a aria-hidden="true" tabindex="-1" href="#推流"><span class="icon icon-link"></span></a>推流</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 推送test.mp4到远程</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-re</span> <span class="token parameter variable">-i</span> test.mp4 <span class="token parameter variable">-f</span> flv rtmp://127.0.0.1/test
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="转发"><a aria-hidden="true" tabindex="-1" href="#转发"><span class="icon icon-link"></span></a>转发</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 拉取流并转发</span>
</span><span class="code-line">$ ffmpeg <span class="token parameter variable">-i</span> <span class="token string">"rtsp://127.0.0.1/test"</span> <span class="token parameter variable">-f</span> mpegts <span class="token parameter variable">-codec:v</span> mpeg1video http://127.0.0.1/demo
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
<ul>
<li><a href="https://ffmpeg.org/">FFmpeg 官网地址</a> <em>(ffmpeg.org)</em></li>
<li><a href="https://lzone.de/cheat-sheet/ffmpeg">FFmpeg Cheat Sheet</a> <em>(lzone.de)</em></li>
<li><a href="https://devhints.io/ffmpeg">FFmpeg Cheat Sheet</a> <em>(devhints.io)</em></li>
<li><a href="https://github.com/yuanqing/ffmpeg-cheatsheet">FFmpeg Cheat Sheet</a> <em>(github.com)</em></li>
<li><a href="https://cheatography.com/thetartankilt/cheat-sheets/ffmpeg/">FFmpeg Cheat Sheet</a> <em>(cheatography.com)</em></li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div><script src="https://giscus.app/client.js" data-repo="jaywcjlove/reference" data-repo-id="R_kgDOID2-Mw" data-category="Q&#x26;A" data-category-id="DIC_kwDOID2-M84CS5wo" data-mapping="pathname" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="bottom" data-theme="dark" data-lang="zh-CN" crossorigin="anonymous" async></script><div class="giscus"></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 <a href="https://wangchujiang.com/#/app" target="_blank">Kenny Wang</a>.</footer></footer><script src="../data.js?v=1.5.5" defer></script><script src="../js/fuse.min.js?v=1.5.5" defer></script><script src="../js/main.js?v=1.5.5" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
